package com.hibiscusking.org.controller;

import com.hibiscusking.basic.util.AjaxResult;
import com.hibiscusking.basic.util.PageList;
import com.hibiscusking.org.domain.SystemDictionaryDetail;
import com.hibiscusking.org.domain.SystemDictionaryType;
import com.hibiscusking.org.query.SystemDictionaryTypeQuery;
import com.hibiscusking.org.service.SystemDictionaryDetailService;
import com.hibiscusking.org.service.SystemDictionaryTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/SystemDictionaryType")
public class SystemDictionaryTypeController {
    @Autowired
    private SystemDictionaryTypeService systemDictionaryTypeService;
    @Autowired
    private SystemDictionaryDetailService systemDictionaryDetailService;
    @GetMapping
    public List<SystemDictionaryType> findAllSystemDictionaryType() {
        return systemDictionaryTypeService.findAll();
    }
    @PutMapping
    public PageList<SystemDictionaryType> findQuerySystemDictionaryType(@RequestBody SystemDictionaryTypeQuery query) {
        return systemDictionaryTypeService.findQuerySystemDictionaryType(query);
    }
    @PostMapping
    public AjaxResult saveSystemDictionaryType(@RequestBody SystemDictionaryType systemDictionaryType) {
        if (systemDictionaryType.getId() == null) {
            systemDictionaryTypeService.add(systemDictionaryType);
        } else {
            systemDictionaryTypeService.update(systemDictionaryType);
        }
        return new AjaxResult().success();
    }
    @DeleteMapping("/{id}")
    public AjaxResult deleSystemDictionaryTypeById(@PathVariable("id") Long id) {
        systemDictionaryDetailService.deleByTypsId(id);
        systemDictionaryTypeService.dele(id);
        return new AjaxResult().success();
    }
}
